import java.util.Arrays;
import java.util.EmptyStackException;

public class MyStack {
    private int[]elem;
    private int usedSize;
    public MyStack() {
        elem = new int[10];
    }
    public void push(int val){
        if(isFull()){
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        elem[usedSize++] = val;
    }
    private boolean isFull(){
        return usedSize == elem.length;
    }
    public int pop(){
        if(usedSize == 0){
            throw new EmptyStackException();
        }
        return elem[--usedSize];
    }

    public int peek(){
        if(usedSize == 0){
            throw new EmptyStackException();
        }
        return elem[usedSize-1];
    }

}
